$(document).ready(function(){
	if (location.href.indexOf("/message") != -1) {
		$("#tomessage").css('color','#28a8b9');
		$("#tomessage").find('img').attr('src','/img/xinxi_dianji.png');
	}else if (location.href.indexOf("/material") != -1) {
		$("#cloudstorage").css('color','#28a8b9');
		$("#cloudstorage").find('img').attr('src','/img/yuncang_dianji.png');
	} else if (location.href.indexOf("/home") != -1) {
		$("#home").css('color','#28a8b9');
		$("#home").find('img').attr('src','/img/daili_dianji.png');
	} else if (location.href.indexOf("/my") != -1) {
		$("#my").css('color','#28a8b9');
		$("#my").find('img').attr('src','/img/wode_dianji.png');
	}else{
		$("#my-modal-searchloading").hide();
	}
});
$(function() {
	//position遇软键盘
	var positon=document.body.clientHeight;
	$('.bottomBar').css('top',positon-55);
    $("#heightsrcoll1,#heightsrcoll2").css("height",positon-40);
    $(".heightsrcoll3").css("height",positon-170);//进货wrapper加载内容高度
    $('.xiadan').css('top',positon-45);
    window.onscroll();
});
//买家订单筛选切换
function checkToptab(item,_this){
    // var types = $(_this).text();
    $(".four").addClass('Cgray');
    $("#guige,#fade").show();
    $('body,.layout_content').css({"overflow":"hidden"});
    $('.layout_content').css({"height":"100%"});
    $(".four1,.four2").find('img').attr('src','/img/order_down.png');
    $('#payserch,#typeserch,#timeserch,#paystatus').addClass('disn');
    switch (item){
        case 'time':
            $(".four1").removeClass('Cgray');
            $(".four1").find('img').attr('src','/img/order_up.png');
            $('#timeserch').removeClass('disn');
			$('.time_').removeClass('disn');
			$('.status_').addClass('disn');
            break;
        case 'type':
            $(".four2").removeClass('Cgray');
            $(".four2").find('img').attr('src','/img/order_up.png');
            $('#typeserch').removeClass('disn');
			$('.status_').removeClass('disn');
			$('.time_').addClass('disn');
            break;
    }
}
/*状态多选*/
function status_one() {
	if ($('.one').hasClass('bg')) {
		$('.one').removeClass('bg');
	}else{
		$('.one').addClass('bg');
	}
}
function status_two() {
	if ($('.two').hasClass('bg')) {
		$('.two').removeClass('bg');
	}else{
		$('.two').addClass('bg');
	}
}
function status_three() {
	if ($('.three').hasClass('bg')) {
		$('.three').removeClass('bg');
	}else{
		$('.three').addClass('bg');
	}
}
//立即支付预约时间显示
function timeShow(){
	ShowDiv();
	var date = new Date(); // new 一个Date对象
	var year = date.getFullYear(); // 年份
	var month = date.getMonth() + 1; // 月份（从0开始，所以应+1）
	var day=date.getDate();
	var days = new Date(year,month,0);
	var lastdate =days.getDate();
	var timeclass='time';
	var labelName='radio';
	var labelClass='disn';
	var labelType="radio";
	var flt='pay-select';
	var clear='clear_both';
	var id='se';
	var border='border1'
	for(var i = day;i <day +7&&i<=lastdate; i++) {
		if(month.toString().length==1){
			month='0'+month;
			//alert(month);
		}
		if(i.toString().length==1){
			i='0'+i;
			//alert(i);
		}
		$("<div class="+border+"><div class="+timeclass+" value="+ year + "-" + month + "-"+ i +">" + year + "-" + month + "-"+ i+"</div><div class="+flt+" id="+id+"><input type="+labelType+" name="+labelName+" class="+labelClass+"><label></label></div><div class="+clear+"></div></div>").appendTo($("#sese"));  // 依次添加下拉框选项，value自定义，右边的appendTo参数为目标选择框    
	    radioFunction();
	}
	if(i>lastdate){
		var month = date.getMonth() + 2;
		if(month>12){
			month=1;
		    year+=1
		}
		for(var i = 1;i <7-(lastdate-day); i++) {
			if(month.toString().length==1){
				month='0'+month;
			}
			if(i.toString().length==1){
				i='0'+i;
			}
			$("<div class="+border+"><div class="+timeclass+" value="+ year + "-" + month + "-"+ i +">" + year + "-" + month + "-"+ i+"</div><div class="+flt+" id="+id+"><input type="+labelType+" name="+labelName+" class="+labelClass+"><label></label></div><div class="+clear+"></div></div>").appendTo($("#sese"));
		    radioFunction();
		}
		//console.log(14-(lastdate-day));
	}
}
//时间显示按钮选择
function radioFunction(){
	$('.pay-select label').click(function(){
	    $(this).addClass('pay-check').parent().parent().siblings().children().children('label').removeClass('pay-check');
	});
	var check=$('#sese').children().eq(0).children().children('label');
	var checksiblings=$('#sese').children().eq(0).siblings().children().children('label');
	check.addClass('pay-check');
    if(checksiblings.hasClass('pay-check')){
    	check.removeClass('pay-check');
    }
}

/**
 * 消息蒙层
 * @constructor
 */
function tip() {
    $('#tip').fadeIn().delay(2500).fadeOut();
}

/**
 * 提交表单显示蒙层
 */
function loadingShow() {
    $("body").css("overflow", "hidden");
    $('#fade').show();
    $('#incommit').removeClass('disn');
    
}

/**
 * 提交表单隐藏蒙层
 */
function loadingHide() {
    $("body").css("overflow", "");
    $('#fade').hide();
    $('#incommit').addClass('disn');
}


//以下为图片懒加载
function setImg(index){
	//alert('setImg');
    var oDiv=$("#lazyloading");
    var aLi=oDiv.find('.lazyimg');
    if (aLi[index].dataset) {
        var src=aLi[index].dataset.src;
    } else{
        var src=aLi[index].getAttribute('data-src');
    }
    var oImg=document.createElement('img');
    oImg.src=src;
    if ($(aLi[index]).children().hasClass('lazy_image_loading')) {
        $(aLi[index]).empty();
        aLi[index].appendChild(oImg);
    }

}
//获得对象距离页面顶端的距离  
function getH(obj) { 
	//alert('setH');
    var h = 0;  
    while (obj) {  
        h += obj.offsetTop;  
        obj = obj.offsetParent;  
    }  
    return h;  
}  
window.onscroll = function () {
	//alert('onscroll');
    var oDiv = $("#lazyloading");
    var aLi=oDiv.find('.lazyimg');
    for (var i = 0, l = aLi.length; i < l; i++) {
        var oLi = aLi[i];
        //检查oLi是否在可视区域
        var t = document.documentElement.clientHeight + (document.documentElement.scrollTop || document.body.scrollTop);
        var h = getH(oLi);
        if (h < t) {
            setTimeout("setImg(" + i + ")" );
        }
    }
};
